//获取应用实例
var app = getApp();
Page({
    data: {
        //处理订单
        orderStatusDoingText:"处理订单",
        orderStatusFinishText:"订单完成",
        orderStatusOneClass: "icon_doing",
        orderStatusThreeClass: "icon_end",
        orderStatusTwoClass: "icon_end",
        orderStatusOneTextClass: "",
        orderStatusTwoTextClass: "",
        orderStatusThreeTextClass: "",
        orderStatusExplainClass: "icon_order_succeed",
        orderStatusLineOneClass: "",
        orderStatusLineTwoClass: "",
        orderStatusLineThreeClass: "",
        isShowPage:false
    },
    onLoad: function (option) {
        var orderId = option.orderId;
        // var orderId = "20170925732496464";
        var pageObj = this;
        var opt = {
            url: app.globalData.host+"/wx/dc/detail.ajax",
            data: {'orderId':orderId},
            sucFn:function (result) {
                var licFeeTmp = pageObj.getMoneyFormat(result.body.licFee);
                var serviceFeeTmp = pageObj.getMoneyFormat(result.body.serviceFee);
                var totalFeeTmp = pageObj.getMoneyFormat(result.body.totalFee);
                pageObj.setData({
                    isShowPage:true,
                    "statusName":result.body.statusName,
                    "statusDescDetail":result.body.statusDescDetail,

                    "serviceFeeDesc":result.body.serviceFeeDesc,
                    "serviceFee":result.body.serviceFee,
                    "cardNbr": result.body.cardNbr,
                    "cardName":result.body.cardName,
                    "certPlaceName":result.body.certPlaceName,

                    "address.contactName":result.body.address.contactName,
                    "address.cellNum":result.body.address.cellNum,
                    "address.fullAddr":result.body.address.fullAddr,

                    "orderId":result.body.orderId,
                    "progressTitle":result.body.progressTitle,
                    "payNo":result.body.payNo,
                    "progressTime":app.toYMDHMSDate(result.body.progressTime),
                    "createTime":app.toYMDHMSDate(result.body.createTime),
                    "completeTime":result.body.completeTime?app.toYMDHMSDate(result.body.completeTime):null,
                    "chargeTime":result.body.chargeTime?app.toYMDHMSDate(result.body.chargeTime):null,
                    "completeTimeText":result.body.status==8?"完成时间":"关闭时间",
                    "needInvoice":result.body.needInvoice,
                    "doc":result.body.doc,
                    "driverName": result.body.driverName,
                    "licCityName": result.body.licCityName,
                    "bizTypeName": result.body.bizTypeName,
                    "licFee": licFeeTmp,
                    "serviceFee": serviceFeeTmp,
                    "totalFee": totalFeeTmp,                    
                });
                switch (result.body.status) {
                    case 2://支付成功
                        switch (result.body.progressStatus){
                            case 1:
                            case 2:
                            case 4:
                            case 5:
                            case 7:
                            case 8:
                                pageObj.setData({
                                    orderStatusDoingText: "处理订单",
                                    orderStatusFinishText: "订单完成",
                                    orderStatusOneClass: "icon_complete",
                                    orderStatusTwoClass: "icon_doing",
                                    orderStatusThreeClass: "",
                                    orderStatusLineOneClass: "bg-colo-00B488",
                                    orderStatusLineTwoClass: "bg-colo-00B488",
                                    orderStatusLineThreeClass: "",
                                    orderStatusOneTextClass: "",
                                    orderStatusTwoTextClass: "state_color_blue",
                                    orderStatusThreeTextClass: "",
                                    orderStatusExplainClass: "icon_order_succeed",
                                    orderStatusLineColour: "bg-color_blue",
                                    orderStatusExplainTextClass: ""
                                });
                                break;
                            case 3://上门收件失败
                            case 6://订单关闭
                                pageObj.setData({
                                    orderStatusDoingText: "处理订单",
                                    orderStatusFinishText: "订单完成",
                                    orderStatusOneClass: "icon_complete",
                                    orderStatusTwoClass: "icon_failing",
                                    orderStatusThreeClass: "",
                                    orderStatusLineOneClass: "bg-colo-00B488",
                                    orderStatusLineTwoClass: "bg-colo-00B488",
                                    orderStatusLineThreeClass: "",
                                    orderStatusOneTextClass: "",
                                    orderStatusTwoTextClass: "state_color_red",
                                    orderStatusThreeTextClass: "",
                                    orderStatusExplainClass: "icon_oeder_close_off",
                                    orderStatusLineColour: "bg-color",
                                    orderStatusExplainTextClass: "color-e64340"
                                });
                                break;
                            default:
                                break;
                        }
                        break;
                    case 3://退单申请中
                        pageObj.setData({
                            orderStatusDoingText: "办理失败",
                            orderStatusFinishText: "订单完成",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_failing",
                            orderStatusThreeClass: "",
                            orderStatusLineOneClass: "bg-colo-00B488",
                            orderStatusLineTwoClass: "bg-colo-00B488",
                            orderStatusLineThreeClass: "",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "state_color_red",
                            orderStatusThreeTextClass: "",
                            orderStatusExplainClass: "icon_oeder_close_off",
                            orderStatusLineColour: "bg-color",
                            orderStatusExplainTextClass: "color-e64340"
                        });
                        break;
                    case 4://订单关闭
                        pageObj.setData({
                            orderStatusDoingText:"办理失败",
                            orderStatusFinishText:"订单关闭",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_fail",
                            orderStatusThreeClass: "icon_failing",
                            orderStatusLineOneClass: "bg-color-red",
                            orderStatusLineTwoClass: "bg-color-red",
                            orderStatusLineThreeClass: "bg-color-red",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "",
                            orderStatusThreeTextClass: "",
                            orderStatusExplainClass: "icon_oeder_close_off",
                            orderStatusLineColour: "bg-color",
                            orderStatusExplainTextClass: "color-e64340"
                        });
                        break;
                    case 8://已完成
                        pageObj.setData({
                            orderStatusDoingText: "处理订单",
                            orderStatusFinishText: "订单完成",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_complete",
                            orderStatusThreeClass: "icon_doing",
                            orderStatusLineOneClass: "bg-colo-00B488",
                            orderStatusLineTwoClass: "bg-colo-00B488",
                            orderStatusLineThreeClass: "bg-colo-00B488",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "state_color_blue",
                            orderStatusThreeTextClass: "state_color_blue",
                            orderStatusExplainClass: "icon_order_succeed",
                            orderStatusLineColour: "bg-color_blue",
                            orderStatusExplainTextClass: ""
                        });
                        break;
                    default://其他
                        break;
                }
            }
        };
        app.ajax(opt);

    },
    getMoneyFormat: function (money) {
      var moneyAtYan = money / 100;
      var moneyResult = "";
      console.log("moneyAtYan:" + moneyAtYan);
      moneyResult = moneyAtYan;
      return moneyResult;
    },
    onHide:function () {
        app.removeStorageSync(app.globalData.cacheOrderResKey);
    },
    progressTap:function(e){
        var orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../progress/progress?orderId='+orderId
        });
    },
    formatCardNum:function (cardNum) {
        return cardNum.substr(0, 6) + "******" + cardNum.substr(cardNum.length - 2, cardNum.length);
    },
    formatTel:function (tel) {
        return tel;
        // return tel.substr(0, 3) + "****" + tel.substr(tel.length - 4, tel.length);
    }
});
